package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.pojo.BlackList;
import com.tanhua.common.mapper.BlackListMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BlackService {

    @Autowired
    private BlackListMapper blackListMapper;


    /**
     * 查询黑名单
     *
     * @param userId
     * @param page
     * @param pageSize
     */
    public IPage<BlackList> queryBlackList(Long userId, Integer page, Integer pageSize) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId).orderByDesc("created");
        // 分页
        IPage<BlackList> pager = new Page<>(page,pageSize);

        return this.blackListMapper.selectPage(pager,wrapper);
    }

    /**
     * 黑名单-删除
     *
     * @param blackUserId
     * @param userId
     * @return
     */
    public Boolean deleteBlack(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("black_user_id",blackUserId);
        return this.blackListMapper.delete(queryWrapper) > 0;

    }
}
